package com.jd.controller;

import com.jd.pojo.Admin;
import com.jd.service.AdminService;
import com.jd.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin")
@CrossOrigin //跨域
public class AdminController {

    @Autowired
    private AdminService adminService;

    @PostMapping("/login")
    @Transactional //事务注解
    public SysResult login(@RequestBody Admin admin){
        String token = adminService.login(admin);
        if (token==null){
            return SysResult.fail();
        }
        return SysResult.success(token);
    }
    @GetMapping("/all/{id}")
    public Admin selectAll(@PathVariable Integer id){
        return adminService.selectAll(id);
    }
}
